package tw.miku.protocol.codec.user;

import org.apache.mina.core.buffer.IoBuffer;

import tw.miku.constants.ProtocalConstants;
import tw.miku.protocol.codec.AbstractRequestMessagePack;
import tw.miku.util.BufferUtility;

public class TalkRequestPack extends AbstractRequestMessagePack
{

	public int userId;
	public int roomId;
	public String message;

	public TalkRequestPack(IoBuffer buffer)
	{
		super(buffer);
	}

	@Override
	public void decode()
	{
		super.decode();
		buffer.position(4);
		userId = (int) buffer.getUnsignedInt();
		roomId = buffer.getInt();
		message = BufferUtility.readString(buffer);
	}

	@Override
	public short getTag()
	{
		return ProtocalConstants.TALK;
	}

	public IoBuffer getInfo()
	{
		buffer.position(0);

		int length = buffer.limit();
		IoBuffer output = IoBuffer.allocate(length + 4);
		output.putUnsignedInt(length);
		output.put(buffer);
		output.flip();
		return output;
	}
}
